using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DataTransferObject;
using DataAccess;

namespace DataAccess
{
    public class clsTuaSachDAO:clsDataAccessHelper
    {
        // Fields
        private String tenTable;

        // Contructors
        public clsTuaSachDAO()
        {
            this.tenTable = "TUASACH";
        }
        #region Methods
        //-------------------------------------Lấy dữ liệu bảng Tựa Sách-----------------------

        public DataTable SelectAll()
        {
            String sql;
            DataTable dt;
            try
            {
                sql = "SELECT * FROM " + this.tenTable;
                dt = new DataTable();
                dt = this.ExecuteQuery(sql);

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //-----------------------------------------------------------------------------//

        //-------------------------------------Thêm vào bảng Tựa Sách-----------------------

        public bool Insert(clsTuaSachDTO tuasach)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "Set dateformat dmy INSERT INTO " + this.tenTable;
                sql += " values('";
                sql += tuasach.MaTuaSach + "',N'";
                sql += tuasach.TenTuaSach + "','";
                sql += tuasach.MaTL + "','";
                sql += tuasach.MaNXB + "','";
                sql += tuasach.MaTG + "','";
                sql += tuasach.MaNN + "',N'";
                sql += tuasach.TomTat + "','";
                sql += tuasach.NgayNhap.Day + "/" + tuasach.NgayNhap.Month + "/" + tuasach.NgayNhap.Year + "','";
                sql += tuasach.Gia + "','";
                sql += tuasach.SoLuong + "','";
                sql += tuasach.SoTrang + "','";
                sql += tuasach.NamXB + "','";
                sql += tuasach.HinhAnh + "')";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }

        //-----------------------------------------------------------------------------//

        //-------------------------------------Xóa vào bảng Tựa Sách-----------------------
        public bool Delete(clsTuaSachDTO tuasach)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "DELETE ";
                sql += " FROM " + this.tenTable;
                sql += " WHERE MATUASACH LIKE '" + tuasach.MaTuaSach + "'";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }



        //-----------------------------------------------------------------------------//

        //-------------------------------------Sửa vào bảng Tựa Sách-----------------------

        public bool Update(clsTuaSachDTO tuasach)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "Set dateformat dmy UPDATE " + this.tenTable;
                sql += " SET";
                sql += " TENTUASACH = N'";
                sql += tuasach.TenTuaSach + "',";
                sql += " MATL = '";
                sql += tuasach.MaTL + "',";
                sql += " MANXB = '";
                sql += tuasach.MaNXB + "',";
                sql += " MATG = '";
                sql += tuasach.MaTG + "',";
                sql += " MANN = N'";
                sql += tuasach.MaNN + "',";
                sql += " TOMTAT = N'";
                sql += tuasach.TomTat + "',";
                sql += " NGAYNHAP = '";
                sql += tuasach.NgayNhap.Day + "/" + tuasach.NgayNhap.Month + "/" + tuasach.NgayNhap.Year + "',";
                sql += " GIA = '";
                sql += tuasach.Gia + "',";
                sql += " SOLUONG = '";
                sql += tuasach.SoLuong + "',";
                sql += " SOTRANG = '";
                sql += tuasach.SoTrang + "',";
                sql += " NAMXB = '";
                sql += tuasach.NamXB + "',";
                sql += " HINHANH = '";
                sql += tuasach.HinhAnh + "'";
                sql += " WHERE MATUASACH LIKE '";
                sql += tuasach.MaTuaSach + "'";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }


        //-----------------------------------------------------------------------------//


        #endregion
    }
}
